package com.lanlian.cayman.adapter;

import android.content.Context;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lanlian.cayman.R;
import com.lanlian.commonlib.bean.BankInfo;
import com.lanlian.commonlib.common.SystemConfig;
import com.lanlian.imagelib.ShowImageUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <pre>
 *     author : huxiaobo
 *     e-mail : huxiaobo@xlanlian.com
 *     date   : 2018/8/15 16:55
 *     desc   : 提现选择银行卡Adapter
 *     version: 1.0
 * </pre>
 */
public class ChooseBankAdapter extends BaseQuickAdapter<BankInfo, BaseViewHolder> {

    private Map<Integer, Boolean> mMaps = new HashMap<>();
    private List<BankInfo> mList;

    public ChooseBankAdapter(Context context, int layoutResId, List<BankInfo> list) {
        super(layoutResId, list);
        this.mContext = context;
        this.mList = list;
        for (int i = 0; i < mList.size(); i++) {
            mMaps.put(mList.get(i).getId(), false);
        }
    }

    public void setChecked(int id) {
        for (int i = 0; i < mList.size(); i++) {
            mMaps.put(mList.get(i).getId(), false);
        }
        mMaps.put(id, true);
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, BankInfo item) {
        ShowImageUtils.showImageView(mContext, item.getLogo(), SystemConfig.IMG_DEFAULT_BACKGROUND,
                helper.getView(R.id.img_bank_logo));
        helper.setText(R.id.tv_bank_name, String.format("%s（%s）", item.getBankName(),
                item.getCardNo().substring(item.getCardNo().length() - 4, item.getCardNo().length())));
        helper.setChecked(R.id.cb_bank, mMaps.get(item.getId()));
    }

}
